package com.ht.web360.PojServer.controller;

import com.ht.web360.PojServer.service.PojBasicService;
import com.ht.web360.PojServer.service.PojInfoService;
import com.ht.web360.base.dto.PojInfo.dto.PojBasicDto;
import com.ht.web360.base.dto.PojInfo.dto.PojInfoDto;
import com.ht.web360.base.dto.RPage;
import com.ht.web360.base.dto.Res;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/poj")
@Tag(name = "项目信息控制器")
public class PojInfoController {

    private final PojBasicService pojBasicService;
    private final PojInfoService pojInfoService;

    public PojInfoController(PojBasicService pojBasicService, PojInfoService pojInfoService) {
        this.pojBasicService = pojBasicService;
        this.pojInfoService = pojInfoService;
    }

    @Operation(summary = "分页查询项目基本信息")
    @GetMapping("/page/basic")
    public Res<RPage<PojBasicDto>> pageBasicData(
            @RequestParam(value = "current", defaultValue = "1") long current,
            @RequestParam(value = "size", defaultValue = "10") long size
    ) {
        RPage<PojBasicDto> page = pojBasicService.pageBasicData(current, size);
        return Res.ok(page);
    }

    @Operation(summary = "分页查询项目信息")
    @GetMapping("/page")
    public Res<RPage<PojInfoDto>> pagePojInfoDto(
            @RequestParam(value = "current", defaultValue = "1") long current,
            @RequestParam(value = "size", defaultValue = "10") long size
    ) {
        RPage<PojInfoDto> page = pojInfoService.pageInfo(current, size);
        return Res.ok(page);
    }

    @Operation(summary = "通过id获取项目信息")
    @GetMapping("/{id}")
    public Res<PojInfoDto> getById(@PathVariable String id) {
        PojInfoDto byId = pojInfoService.getById(id);
        return Res.ok(byId);
    }

    @Operation(summary = "通过id更新项目信息")
    @PostMapping("/{id}")
    public Res<Void> updateById(@RequestBody PojInfoDto pojInfoDto) {
        pojInfoService.updateById(pojInfoDto);
        return Res.ok();
    }
    
    @Operation(summary = "更新项目封面")
    @PostMapping("/cover/{pojId}")
    public Res<Void> uploadCover(@PathVariable String pojId, MultipartFile file) {
        pojInfoService.uploadCover(pojId, file);
        return Res.ok();
    }

    @Operation(summary = "创建项目信息")
    @PostMapping("/create")
    public Res<Void> create(@RequestBody PojInfoDto pojInfoDto) {
        pojInfoService.savePojInfo(pojInfoDto);
        return Res.ok();
    }

    @Operation(summary = "通过id删除项目信息")
    @GetMapping("/delete/{id}")
    public Res<Void> deleteById(@PathVariable String id) {
        pojInfoService.deleteById(id);
        return Res.ok();
    }
}
